﻿using Liu_Project.Entity.Admin;
using System;
using Liu_Project.Utils;

namespace Liu_Project.Dal.Common
{
    public abstract class DalBase : LSL.SqlClient.BaseDAL
    {
        /// <summary>
        /// 获取用户信息,返回NULL则SESSION过期
        /// </summary>
        public EntUser CurrentUser
        {
            get
            {
                var currentUser = System.Web.HttpContext.Current.Session["CurrentUser"];
                if (currentUser != null)
                {
                    return (EntUser)currentUser;
                }
                else
                {
                    return null;
                }
            }
        }

        public void SetCreateDefaultValue<T>(T entity)
        {
            entity.SetPropertyValue("CreateTime", DateTime.Now);
            entity.SetPropertyValue("CreateUserId", CurrentUser.UserId);
            entity.SetPropertyValue("CreateUserName", CurrentUser.UserName);
            entity.SetPropertyValue("UpdateTime", DateTime.Now);
            entity.SetPropertyValue("UpdateUserId", CurrentUser.UserId);
            entity.SetPropertyValue("UpdateUserName", CurrentUser.UserName);
        }

        public void SetUpdateDefaultValue<T>(T entity)
        {
            entity.SetPropertyValue("UpdateTime", DateTime.Now);
            entity.SetPropertyValue("UpdateUserId", CurrentUser.UserId);
            entity.SetPropertyValue("UpdateUserName", CurrentUser.UserName);
        }
    }
}
